package com.dongrj.framework.starter.log.dingding;

import lombok.extern.slf4j.Slf4j;

/**
 * @author dongrongjun
 * @date 2020/4/2
 */
@Slf4j
public final class NoticeUtils {

    /**
     * 发送钉钉通知
     *
     * @param message 消息
     */
    public static void sendDingDing(String message) {
        sendDingDing(true, message);
    }

    /**
     * 发送钉钉通知
     *
     * @param flag    是否发送
     * @param message 消息
     */
    public static void sendDingDing(boolean flag, String message) {
        DingTalkMsg dingTalkMsg = new DingTalkMsg();
        dingTalkMsg.setFlag(flag);
        dingTalkMsg.setMsgType(MessageType.Original);
        dingTalkMsg.setMessage(message);
        sendDingDing(dingTalkMsg);
    }


    /**
     * 发送钉钉消息，消息内容不做任何改变
     *
     * @param message 消息内容
     */
    public static void sendDingDingExtend(String message) {
        DingTalkMsg dingTalkMsg = new DingTalkMsg();
        dingTalkMsg.setFlag(true);
        dingTalkMsg.setMessage(message);
        sendDingDing(dingTalkMsg);
    }

    /**
     * 发送钉钉通知
     *
     * @param dingDing 消息
     */
    public static void sendDingDing(DingTalkMsg dingDing) {
        if (!dingDing.isFlag()) {
            return;
        }
        try {
            AppStatusDingDingSender.getInstance().send(dingDing);
        } catch (Exception e) {
            log.info("sendDingDing异常!");
        }
    }
}
